﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Collections;
using System.Diagnostics.Contracts;

namespace ShredTheLog.Converters
{
    [ValueConversion(typeof(bool), typeof(object))]
    public sealed class IifConverter : ConverterBase, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var condition = (bool)value;
            var values = (IList)parameter;
            Contract.Assume(values.Count == 2);
            return condition ? values[0] : values[1];
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        public static readonly IifConverter Default = new IifConverter();
    }
}
